<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('planhj/index')}">列表</a></li>
        <li class="active"><a>添加</a></li>
    </ul>
    <php> $statusarr=array(1=>"已下发",2=>"进行中",3=>"已完成"); $sta=1;</php>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20"  id="ljz-form-search" >
        <input type="hidden" name="plan_id" value="{$info['id']}">

      <table class="table table-hover table-bordered">
                <tr>
                    <td>计划类型</td>
                    <td>{$type_id_arr[$infod['type']]|default=''}</td>
                    <td>捆包号</td>
                    <td>  <if condition="$infod['plate_id']">
                        <php>$infod['plate_id']=explode(',',  $infod['plate_id']);</php>
                        <foreach name="$infod['plate_id']" item="vo1">
                            {$plate_id_arr_da[$vo1]}
                        </foreach>
                    </if></td>
                    <td>计划号</td>
                    <td>{$infod['name']}</td>
                    <td>归属类型</td>
                    <td>{$companytypea_arr[$infod['companytype']]|default=''}</td>
                    <td>状态</td>
                    <td>{$statusarr[$infod['status']]|default=''}</td>

                    </td>
                </tr>
          <tr>
              <td>合同编号</td>
              <td> {$ht_id_arr_co[$infod['ht_id']]|default=''}</td>
              <td>客户名称</td>
              <td> {$company_id_arrd_co[$infod['company_id']]|default=''}</td>
              <td>牌号</td>
              <td> {$grade_id_arr_co[$infod['grade_id']]|default=''}</td>
              <td>钢种</td>
              <td>{$steel_grade_id_arr_co[$infod['steel_grade_id']]|default=''}</td>
              <td>交付时间</td>
              <td>{:date('Y-m-d H:i',$infod['delivery_time'])}</td>
          </tr>
          <tr>
              <td>生产日期</td>
              <td>  {:date('Y-m-d H:i',$infod['pd'])}</td>
              <td>钢卷信息</td>
              <td> <if condition="$infod['coil_id']">
                  <php>$infod['coil_id']=explode(',',  $infod['coil_id']);</php>
                  <foreach name="$info['coil_id']" item="vo1">
                      {$coil_id_arr[$vo1]}
                  </foreach>
              </if></td>
              <td>厚</td>
              <td>  {$infod['d']}</td>
              <td>宽</td>
              <td>  {$infod['w']}</td>
              <td>长</td>
              <td>  {$infod['h']}</td>
          </tr>
          <tr>
              <td>张数</td>
              <td>  {$infod['sheets']}</td>
              <td>图片附件</td>
              <td>    <button onclick="detail({$infod.id},'image_enclosure')" type="button" class="btn btn-info">查看</button>           </td>
              <td>文件附件</td>
              <td> <button onclick="detail({$infod.id},'file_enclosure')" type="button" class="btn btn-info">查看</button></td>
              <td>备注</td>
              <td>   {$infod['remrk']}</td>
              <td>添加时间</td>
              <td> {:date('Y-m-d H:i',$infod['add_time'])}</td>
          </tr>
      </table>

        <foreach name="$info['plate_id']" item="vo">


            <div class="form-group" id="plate_id_{$vo}">
                <label class="col-sm-1 control-label"><span class="form-required"></span> 钢板号:</label>
                <div class="col-md-4 col-sm-10">
                    {$plate_id_arr_da[$vo]}
                    <a class="btn btn-xs btn-primary" onclick="addkun({$vo})">钢板入库</a>
                </div>
            </div>
        </foreach>
        <div class="col-sm-offset-2 col-sm-10">
<!--            <button type="submit" class="btn btn-primary js-ajax-submit">保存</button>-->
            <button class="btn btn-primary" id="bt_search">保存</button>
            <button class="btn btn-primary" id="bt_output">保存并结束</button>
            <a class="btn btn-default" href="{:url('planhj/index')}">返回</a>
        </div>
    </form>

</div>

<script src="/static/js/admin.js"></script>
<script src="/static/js/layer/layer.js"></script>
<script>
    // var coil_count = new Array();

    // <foreach name="$info['coil_id']" item="vo">
    //
    //
    //     coil_count[{$vo}]=100;
    //
    //
    // </foreach>

    $(function () {
        // 条件查询
        $("#bt_search").click(function(){
            $("#ljz-form-search").removeAttr('action');
            $("#ljz-form-search").attr('action',"{:url('Plate/platesaddPostnew1')}" );
            $("#ljz-form-search").submit();
        });
        //保存并结束
        $("#bt_output").click(function(){
            $("#ljz-form-search").removeAttr('action');
            $("#ljz-form-search").attr('action',"{:url('Plate/platesaddPostnew')}");
            $("#ljz-form-search").submit();
        });
    });

    coil_count=100;
    function addkun(id) {
        var plate_id;
        var platearray = new Array();
        platearray = {$platearray};
       // console.log()
        var coil_id_arr_da1 = new Array();
        coil_id_arr_da1 = {$coil_id_arr_da1};

        var plate_id_arr_da1 = new Array();
        plate_id_arr_da1 = {$plate_id_arr_da1};

        var steel_grade_id_arr = new Array();
        steel_grade_id_arr = {$steel_grade_id_arr};

        var ht_id_arr = new Array();
        ht_id_arr = {$ht_id_arr};

        var company_id_arr = new Array();
        company_id_arr = {$company_id_arr};

        var grade_id_arr = new Array();
        grade_id_arr = {$grade_id_arr};
        //获取钢卷号
        $.ajax({
                url: '{:url("plate/getname")}',
                type: 'get',
                success(res) {

                    plate_id=res.data
                    // id="div_is_starting_price_' + id + '_' + coil_count[id] + '"
                    //
                    html = '<table class="table table-hover table-bordered table-list"  id="div_is_starting_price_' + id + '_' + coil_count + '">' +
                        ' <tr>' +
                        '<td>类型:</td>' +
                        '<td> <select name="post[' + coil_count + '][type]" class="form-control" id="'+coil_count+'type" onchange="selectchange('+coil_count+')"> \n' +
                        '                    <option value="0">请选择</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="1">selected</if>\n' +
                        '                    value="1">成品库</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="2">selected</if>\n' +
                        '                    value="2">实验库</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="3">selected</if>\n' +
                        '                    value="3">废料库</option>\n' +
                        '                    <option\n' +
                        '                    selected\n' +
                        '                    value="4">半成品库</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="3">selected</if>\n' +
                        '                    value="5">头尾库</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="3">selected</if>\n' +
                        '                    value="6">封闭库</option>\n' +
                        '                    <option\n' +
                        '                    <if isset($vo.type)&&$vo.type=="7">selected</if>\n' +
                        '                    value="7">样品库</option>\n' +
                        '                </select></td>' +

                        '<td>成品牌号:</td>' +
                        '<td>' + grade_id_arr[{$info['grade_id']}] + '' +
                        ' <input  type="hidden" class="form-control" value="{$info['grade_id']}" name="post['+coil_count+'][grade_id]"></td>' +
                    '<td>原料钢种:</td>' +
                    '<td>' + steel_grade_id_arr[{$info['steel_grade_id']}] + '' +
                    ' <input  type="hidden" class="form-control" value="{$info['steel_grade_id']}" name="post['+coil_count+'][steel_id]"></td>' +
                    '<td>合同号:</td>' +
                    '<td>' + ht_id_arr[{$info['ht_id']}] + '' +
                    ' <input  type="hidden" class="form-control" value="{$info['ht_id']}" name="post['+coil_count+'][ht_id]"></td>' +
                    '<td>归属:</td>' +
                    '<td > <input placeholder="" type="text" class="form-control" readonly value="{$info['companytype']}" name="post[' + coil_count + '][companytype]"></td>' +

                    '</tr>' +
                    '<tr>' +
                    '<td>捆包号:</td>' +
                    '<td> <input placeholder="" type="text" value="'+plate_id+'" id="'+coil_count+'name" class="form-control" name="post['+coil_count+'][name]"></td>' +

                    '<td>原捆包号:</td>' +
                    '<td>' + plate_id_arr_da1[id] + '' +
                    ' <input  type="hidden" class="form-control" value="' + id + '" name="post['+coil_count+'][parent_id]"></td>' +
                    '<td>厚:</td>' +
                    '<td> <input placeholder="" type="text" class="form-control" value="{$info['d']}" name="post['+coil_count+'][d]"></td>' +
                    '<td>宽:</td>' +
                    '<td> <input placeholder="" type="text" class="form-control" value="{$info['w']}" name="post['+coil_count+'][w]"></td>' +
                    '<td>长:</td>' +
                    '<td> <input placeholder="" type="text" class="form-control" value="{$info['h']}" name="post['+coil_count+'][h]"></td>' +
                    '</tr><tr>' +
                    '<td>张数:</td>' +
                    '<td> <input placeholder="" type="text" class="form-control" value="'+platearray[id]['sheets']+'" name="post['+coil_count+'][sheets]"></td>' +
                    '<td>重量:</td>' +
                    '<td> <input placeholder="" type="text" class="form-control"  value="'+platearray[id]['weight']+'" name="post['+coil_count+'][weight]"></td>' +
                    '<td>库位:</td>' +
                    '<td > <input placeholder="" type="text" class="form-control"  name="post['+coil_count+'][kuwei]"></td>' +
                    '<td>备注:</td>' +
                    '<td colspan="6"> <input placeholder="" type="text" class="form-control"  name="post['+coil_count+'][remark]"></td>' +
                    '<td><a class="btn btn-xs btn-danger" onClick="remove(\'div_is_starting_price_' + id + '_' + coil_count + '\')">移除</a></td>' +
                    '</tr></table>';
                    idss = '#plate_id_' + id
                    jQuery(idss).append(html);
                    coil_count++

                }
            }
        )


    }
    function selectchange(count){
        // alert(count+'type');
        id='#'+count+'type';
        var type = $(id).val()
        // alert(type);
        if (type>0){
            $.ajax({
                type: "POST",
                url: "{:url('plate/getname')}",
                contentType: "application/json", //如果提交的是json数据类型，则必须有此参数,表示提交的数据类型
                // dataType: "json", //表示返回值类型，不必须
                data:type,
                success: function (res) {
                    // $("#plate_id").html("");
                    //在原来的页面跳转到下载word模板的页面
                    console.log(res)
                    if (res.code == 1 && res.data != '') {
                        $( '#'+count+'name').val(res.data);

                    }
                },
                error: function (data) {
                    alert("钢板接口请求失败，请联系管理员");
                }
            });
        }
    }
        function remove(ids) {
            console.log(ids)
            ids = "#" + ids;
            jQuery(ids).remove();
            // $("#div1").empty();
        }


    function detail(id, field) {
        $.ajax({
            url: '{:url("Plan/field")}?id=' + id + '&field=' + field,
            type: 'get',
            success(res)
        {
            if (res.code == 1) {
                let tpl = '';
                for (const item of res.data) {
                    tpl += `<p>地址：<input value="${item.filename}" readonly class="form-control" style="width:80%;display: inline-block;" type="text">&nbsp;<a target="_blank" href="{$domain}${item.file_path}" class="btn btn-success">跳转</a></p>`;
                }
                layer.open({
                    area: ['60%', '100%'],
                    content: tpl
                });
            } else {
                layer.msg('查看失败');
            }
        }
    })
        ;
    }
</script>
</body>
</html>